import 'package:auto_size_text/auto_size_text.dart';
import 'package:easy_rich_text/easy_rich_text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:rich_readmore/rich_readmore.dart';
import 'package:rich_text_view/rich_text_view.dart';

class TestSpannableWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MApp();
  }
}

class _MApp extends State<TestSpannableWidget> {
  final _tapRecognizer = TapGestureRecognizer();

  @override
  void dispose() {
    _tapRecognizer.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Spannable"),
      ),
      body: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            AutoSizeText(
              'The text to di洒大o di洒大o di洒大o di洒大o di洒大o 大o di洒大o di洒大o di洒大o 大o di洒大o di洒大o di洒大o 大o di洒大o di洒大o di洒大o 大o di洒大o di洒大o di洒大o 大o di洒大o di洒大o di洒大o 大o di洒大o di洒大o di洒大o 大o di洒大o di洒大o di洒大o 大o di洒大o di洒大o di洒大o 大o di洒大o di洒大o di洒大o 大o di洒大o di洒大o di洒大o di洒大o di洒大o di洒大o di洒大o di洒大o di洒大o di洒大o di洒大o di洒大地asplay',
              style: TextStyle(fontSize: 20),
              maxLines: 4,
              overflow: TextOverflow.ellipsis,
            ),
            Text(
              "asdadsasdasasdadsasdasasdadsasdasasdadsasdasasdadsasdasasdadsasdasasdadsasdasasdadsasdasasdadsasdasasdadsasdasd",
              overflow: TextOverflow.ellipsis,
              maxLines: 2,
            ),
            AutoSizeText.rich(TextSpan(children: [
              TextSpan(text: "Home: "),
              TextSpan(
                  text: "https://flutterchina.club",
                  style: TextStyle(color: Colors.blue),
                  recognizer: _tapRecognizer
                    ..onTap = () {
                      print("Adasdasdasd");
                    }),
            ])),
            EasyRichText(
              "I want blue font. I want bold font. I want italic font.",
              patternList: [
                EasyRichTextPattern(
                  targetString: 'blue',
                  style: TextStyle(color: Colors.blue),
                ),
                EasyRichTextPattern(
                  targetString: 'bold',
                  style: TextStyle(fontWeight: FontWeight.bold),
                ),
                EasyRichTextPattern(
                  targetString: 'italic',
                  style: TextStyle(fontStyle: FontStyle.italic),
                ),
              ],
            ),
            EasyRichText(
              "ProductTM is a superscript trademark symbol. This TM is not a trademark.",
              patternList: [
                EasyRichTextPattern(
                  targetString: 'TM',
                  superScript: true,
                  stringBeforeTarget: 'Product',
                  matchWordBoundaries: false,
                  style: TextStyle(color: Colors.blue),
                ),
              ],
            ),
            EasyRichText(
              "This is a EasyRichText example with default grey font. I want blue font here.",
              defaultStyle: TextStyle(color: Colors.grey),
              patternList: [
                EasyRichTextPattern(
                  targetString: 'blue',
                  style: TextStyle(color: Colors.blue),
                ),
                EasyRichTextPattern(
                  targetString: 'bold',
                  style: TextStyle(fontWeight: FontWeight.bold),
                ),
              ],
            ),
            EasyRichText(
              "I want blue color here. I want no blue font here. I want blue invalid here.",
              patternList: [
                EasyRichTextPattern(
                  targetString: 'blue',
                  stringBeforeTarget: 'want',
                  stringAfterTarget: "color",
                  style: TextStyle(color: Colors.blue),
                ),
              ],
            ),
            EasyRichText(
              "blue 1, blue 2, blue 3, blue 4, blue 5",
              patternList: [
                EasyRichTextPattern(
                  targetString: 'blue',
                  //matchOption: 'all'
                  matchOption: [0, 1, 'last'],
                  style: TextStyle(color: Colors.blue),
                ),
              ],
            ),
            EasyRichText(
              "I want superscript font here. I want subscript here",
              patternList: [
                EasyRichTextPattern(targetString: 'superscript', superScript: true),
                EasyRichTextPattern(targetString: 'subscript', subScript: true),
              ],
            ),
            EasyRichText(
              "Case-Insensitive String Matching. I want both Blue and blue. This paragraph is selectable.",
              caseSensitive: false,
              selectable: true,
              patternList: [
                EasyRichTextPattern(
                  targetString: 'Blue',
                  style: TextStyle(color: Colors.blue),
                ),
              ],
            ),
            EasyRichText(
              "This paragraph is selectable...",
              selectable: true,
            ),
            RichReadMoreText(
              TextSpan(children: [
                TextSpan(
                    text:
                        "Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home:Home: "),
                TextSpan(
                    text: "https://flutterchina.club",
                    style: TextStyle(color: Colors.blue),
                    recognizer: _tapRecognizer),
              ]),
              settings: LineModeSettings(
                trimLines: 3,
                trimCollapsedText: '展开',
                moreStyle: TextStyle(color: Colors.blue),
                trimExpandedText: '关闭',
                lessStyle: TextStyle(color: Colors.red),
                onPressReadMore: () {
                  print(" 点击展开");
                },
                onPressReadLess: () {
                  print(" 点击关闭");
                },
              ),
            ),
            RichTextView(
                text: '''Who else thinks it's thinks it's just cool to mention 
                      @jane when #JaneMustLive is trending without even trying 
                      to send a *bold* email to janedoe@gmail.com and verify the
                       facts talkmore of visiting www.janedoe.com''',
                maxLines: 3,
                truncate: true,
                viewLessText: 'less',
                linkStyle: TextStyle(color: Colors.blue),
                supportedTypes: [
                  EmailParser(onTap: (email) => print('${email.value} clicked')),
                  PhoneParser(onTap: (phone) => print('click phone ${phone.value}')),
                  MentionParser(onTap: (mention) => print('${mention.value} clicked')),
                  UrlParser(onTap: (url) => print('visting ${url.value}?')),
                  BoldParser(),
                  HashTagParser(onTap: (hashtag) => print('is ${hashtag.value} trending?'))
                ]),
            RichTextView(
              text:
                  "Who else thinks it's thinks it's just cool to mention@jane when #JaneMustLive is trending without even trying to send a *bold* email to janedoe@gmail.com and verify the facts talkmore of visiting www.janedoe.com",
              maxLines: 3,
              truncate: true,
              viewLessText: '关闭',
              viewMoreText: "展开",
              overflow:  TextOverflow.ellipsis,
              linkStyle: TextStyle(color: Colors.blue),
              supportedTypes: [],
            ),
            RichTextView(
              text:
              "asdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasasdasd",
              maxLines: 2,
              truncate: true,
              viewLessText: '关闭',
              viewMoreText: "展开",
              overflow:  TextOverflow.visible,
              linkStyle: TextStyle(color: Colors.blue),
              supportedTypes: [],
            ),
            Text( ' \u2026')
          ],
        ),
      ),
    );
  }
}
